package com.koicarp.university.graduate.web.controller;

import com.koicarp.university.graudate.common.constant.BaseConstant;
import com.koicarp.university.graudate.common.entity.log.LogOperateInfo;
import com.koicarp.university.graduate.service.service.log.ILogOperateInfoService;
import com.koicarp.university.graudate.common.utils.UniversityResponse;
import com.koicarp.university.graudate.common.vo.OperateInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 【日志管理：操作日志信息表】(LogOperateInfo)表控制层
 *
 * @author liutao
 * @since 2020-09-03 19:53:52
 */
@RestController
@RequestMapping("logOperateInfo")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "(日志管理)表控制层")
public class LogOperateInfoController {
    /**
     * 服务对象
     */
    private final ILogOperateInfoService logOperateInfoService;

    @PostMapping("getOperateInfoWithPage")
    @ApiOperation(value = "日志管理-分页查询日志",notes = "分页查询日志")
    public UniversityResponse getOperateInfoWithPage(OperateInfoVo vo){
        UniversityResponse response=null;
        try{
            response = logOperateInfoService.queryOperateInfoWithPage(vo);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("removeInfo")
    @ApiOperation(value = "日志管理-分页查询日志",notes = "分页查询日志")
    public UniversityResponse removeInfo(@RequestBody OperateInfoVo vo){
        UniversityResponse response=null;
        try {
            response = logOperateInfoService.deleteById(Long.valueOf(vo.getId()));
        }catch (Exception e){
            log.error("删除失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("removeLogListInfo")
    @ApiOperation(value = "根据id删除日志",notes = "批量删除")
    public UniversityResponse removeLogListInfo(@RequestBody List<String> list){
        UniversityResponse response=null;
        try{
            response = logOperateInfoService.deleteListById(list);
        }catch (Exception e){
            log.error("删除日志失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

}